<!--
  - Copyright (c) 2018.
  - 北京九思金信科技有限公司对该文件内容保留所有权利。
  - 未经许可，不得私自拷贝、传播、发布、引用该文件内容，违者将被追究法律责任。
  -->
  <template>
  <div class="sueSearch_box">
    <div class="sueSearch_title">
      <div class="search_box">
        <img src="@/assets/img/Back@3x.png" @click="returnHistoy" alt>
        <input type="text" :placeholder="placeholder" maxlength="20" v-model="searchInfo">
      </div>
      <i @click="returnHistoy">取消</i>
    </div>
    <div  class="sueSearch_list">
      <div class="sueSearch_list_item" v-for="item in searchlist" :key="item.id">
        <div class="sueSearch_list_item_img">
          <img v-lazy="queryImg(item.appImgId)" alt>
        </div>
        <div class="sueSearch_list_item_info">
          <p>{{item.appletName}}</p>
        </div>
      </div>
    </div>
    <div v-if="!searchlist.length && searchInfo " class="sueSearch_none_list">没有搜索到任何关于“{{searchInfo}}”的应用</div>
    <div v-show="!searchlist.length && !searchInfo" class="sueSearch_none_list">{{searchName}}</div>
  </div>
</template>
  
  <script>
  import { myDOM } from "@/assets/js/utils.js";
export default {
  name: "JoysSearch",
props:{
    placeholder: {
      type: String,
      default: '搜索'
    },
    searchName:{
        type:String,
        default:"请输入搜索内容"
    }

},
  data() {
    return {
      searchInfo:"",
      searchlist: []
    };
  },
  watch: {
    searchInfo(){
      // setTimeout
      setTimeout(() => {
        this.searchInfoList()
      }, 200);
    }
  },
  methods: {
    searchInfoList(){
      this.$axios({
        url:"/joys-rest/joys-master-data/applets",
        method:"get",
        headers: {
          "AUTH-TOKEN": localStorage.getItem("AUTH-TOKEN")
        },
        params:{
          appletName: this.searchInfo,
          typeTags: ["MAPP"]
        }
      }).then(res => {
          this.searchlist = res.data;
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 请求图片
    queryImg(id){
      return (
        this.$baseUrl+"/joys-rest/joys-file/file/browse/one2one/" +
        id +
        "?AUTH-TOKEN=" +
        localStorage.getItem("AUTH-TOKEN")
      );
    },
    returnHistoy() {
      this.$router.goBack();
    }
  },
  created () {
    // 节流
    this.$watch('searchInfo', myDOM.debounce((newQuery) => {
      this.searchInfoList()
    }, 300))
  },
};
</script>
  
  <style scoped lang="less">
.sueSearch_box {
  position: fixed;
  top: 0rem;
  bottom: 0.1rem;
  width: 100%;
  height: 100%;
  z-index: 300;
  background: #ffffff;
  .sueSearch_title {
    height: 0.44rem;
    width: 100%;
    background: #ffffff;
    box-shadow: inset 0 -1px 0 0 rgba(207, 207, 207, 0.2);
    position: relative;
    overflow: hidden;
    .search_box {
      position: absolute;
      top: 0rem;
      left: 0rem;
      width: 100%;
      line-height: 0.44rem;
      height: 0.44rem;
      img {
        width: 0.2rem;
        position: absolute;
        // left: 0.085rem;
        // top: 0.12rem;
        top: 0rem;
        left: 0rem;
        padding: 0.12rem 0.085rem;
      }
      input {
        padding-left: 0.1rem;
        height: 0.32rem;
        background: rgba(141, 141, 141, 0.05);
        font-family: Regular;
        font-size: 0.14rem;
        color: #001616;
        letter-spacing: -0.34px;
        line-height: 0.14rem;
        margin-top: -0.05rem;
        margin-left: 0.36rem;
        width: 100%;
      }
      input::placeholder {
        font-family: Regular;
        font-size: 0.14rem;
        color: #c6c6c6;
        letter-spacing: -0.34px;
        line-height: 0.14rem;
      }
    }
    i {
      display: block;
      height: 0.43rem;
      width: 0.63rem;
      line-height: 0.44rem;
      text-align: center;
      font-family: Regular;
      font-size: 0.14rem;
      color: #001616;
      letter-spacing: -0.34px;
      position: absolute;
      top: 0rem;
      right: 0rem;
      background: #ffffff;
    }
  }
  .sueSearch_list {
    background: #ffffff;
    .sueSearch_list_item {
      height: 0.56rem;
      margin-left: 0.18rem;
      padding-right: 0.16rem;

      border-bottom: 1px rgba(207, 207, 207, 0.2) solid;
      .sueSearch_list_item_img {
        float: left;
        width: 0.24rem;
        height: 100%;
        // background: red;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 0.16rem;
        img {
          height: 0.24rem;
        }
      }
      .sueSearch_list_item_info {
        height: 0.56rem;

        p {
          display: block;
          height: 0.56rem;
          font-family: Regular;
          font-size: 0.15rem;
          color: #535353;
          letter-spacing: -0.36px;
          line-height: 0.56rem;
        }
      }
    }
  }
  .sueSearch_none_list {
    font-family: Regular;
    font-size: 0.13rem;
    color: rgba(0, 22, 22, 0.8);
    letter-spacing: 0;
    text-align: center;
    margin-top: 30%;
  }
}
</style>
